<!-- component-name -->
<template>
  <div class='wrapper'>
    <el-form label-width="120px">
      <el-form-item label="医院名称" required>
        <el-input v-model="hospitalSet.hosname" />
      </el-form-item>
      <el-form-item label="医院编号" required>
        <el-input v-model="hospitalSet.hoscode" />
      </el-form-item>
      <el-form-item label="api基础路径" required>
        <el-input v-model="hospitalSet.apiUrl" />
      </el-form-item>
      <el-form-item label="联系人姓名" required>
        <el-input v-model="hospitalSet.contactsName" />
      </el-form-item>
      <el-form-item label="联系人手机" required>
        <el-input v-model="hospitalSet.contactsPhone" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveOrUpdate">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  saveHospitalSet,
  getHospitalSet,
  updateHospitalSet,
} from "@/api/hospset";

export default {
  name: "component-name",
  data() {
    return {
      hospitalSet: {},
      id: 0,
    };
  },
  methods: {
    saveOrUpdate() {
      if (this.id === 0) {
        saveHospitalSet(this.hospitalSet).then((response) => {
          //提示
          this.$message({
            type: "success",
            message: "添加成功!",
          }); //跳转列表页面，使用路由跳转方式实现
          this.$router.push({ path: "/hospset/list" });
        });
      } else {
        updateHospitalSet(this.hospitalSet).then((response) => {
          //提示
          this.$message({
            type: "success",
            message: "修改成功!",
          }); //跳转列表页面，使用路由跳转方式实现
          this.$router.push({ path: "/hospset/list" });
        });
      }
    },
  },
  created() {
    if (this.$route.params && this.$route.params.id) {
      this.id = this.$route.params.id;
      getHospitalSet(this.id)
        .then((res) => {
          this.hospitalSet = res.data;
        })
        .catch((err) => {
          this.$message.error(err.message);
        });
    }else {
      this.hospitalSet = {}
    }
  },
};
</script>
<style lang='scss' scoped>
// @import url();
.wrapper {
  padding: 20px 10px;
}
</style>
